package com.demohomework.homeworkdemo.mapper;

import com.demohomework.homeworkdemo.pojo.Class;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ClassMapper {
    @Insert("insert into sc(id,stu_id,cou_id) values(#{id},,#{stuId},#{couId})")
    void add(Class cls);

    @Select("select * from sc")
    List<Class> list(Integer id);

    @Select("select * from sc where id = #{id} ")
    Class findId(Integer id);

    @Update("update sc set stu_id = #{stuId}, cou_id = #{couId} where id = #{id}")
    void update(Class cls);

    @Delete("delete from sc where id = #{id}")
    void delete(Class cls);

    //根据学生id查找课程
    @Select("SELECT * FROM sc WHERE stu_id = #{stuId}")
    List<Class> findByStudentId(Integer stuId);

    //根据课程id查找所有学生
    @Select("SELECT * FROM sc WHERE cou_id = #{couId}")
    List<Class> findByCourseId(Integer courseId);

    @Delete("DELETE FROM sc WHERE stu_id = #{stuId} AND cou_id = #{couId}")
    void deleteByStudentIdAndCourseId(Integer stuId, Integer couId);
}
